<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="ObjectToOperate"></xsl:param>  
  <xsl:template match="/DataSet">public partial class AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity
  {
    #region Properties
    <xsl:for-each select="Table">
    public <xsl:value-of select="DataType"/><xsl:text> </xsl:text><xsl:value-of select="Variable"/> {get; set;}
    </xsl:for-each>
    #endregion

    #region Constructor
    public AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity()
    {

    }
    #endregion

    #region  Methods

    #region Private Methods

    static AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity BuildEntity(DataRow dataRow)
    {
      AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity item = new AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity
      {
        <xsl:for-each select="Table">
        <xsl:if test="DataType = 'int'">
          <xsl:value-of select="Variable"/> = (dataRow.Table.Columns.Contains("<xsl:value-of select="Variable"/>")) ? dataRow["<xsl:value-of select="Variable"/>"] != DBNull.Value ? dataRow.Field<xsl:text disable-output-escaping="yes">&lt;int&gt;</xsl:text>("<xsl:value-of select="Variable"/>") : Int32.MinValue : Int32.MinValue<xsl:if test="position() != last()">,
          </xsl:if>
        </xsl:if>
        <xsl:if test="DataType = 'DateTime'">
          <xsl:value-of select="Variable"/> = (dataRow.Table.Columns.Contains("<xsl:value-of select="Variable"/>")) ? dataRow["<xsl:value-of select="Variable"/>"] != DBNull.Value ? dataRow.Field<xsl:text disable-output-escaping="yes">&lt;DateTime&gt;</xsl:text>("<xsl:value-of select="Variable"/>") : DateTime.MinValue : DateTime.MinValue<xsl:if test="position() != last()">,
          </xsl:if>
        </xsl:if>
        <xsl:if test="DataType = 'bool'">
          <xsl:value-of select="Variable"/> = (dataRow.Table.Columns.Contains("<xsl:value-of select="Variable"/>")) ? dataRow["<xsl:value-of select="Variable"/>"] != DBNull.Value ? dataRow.Field<xsl:text disable-output-escaping="yes">&lt;bool&gt;</xsl:text>("<xsl:value-of select="Variable"/>") : false : false<xsl:if test="position() != last()">,
          </xsl:if>
        </xsl:if>
        <xsl:if test="DataType = 'string' or DataType = 'String' ">
          <xsl:value-of select="Variable"/> = (dataRow.Table.Columns.Contains("<xsl:value-of select="Variable"/>")) ? dataRow["<xsl:value-of select="Variable"/>"] != DBNull.Value ? dataRow.Field<xsl:text disable-output-escaping="yes">&lt;string&gt;</xsl:text>("<xsl:value-of select="Variable"/>") : string.Empty : string.Empty<xsl:if test="position() != last()">,
          </xsl:if>
        </xsl:if>
        <xsl:if test="DataType = 'decimal' or DataType = 'Decimal' ">
          <xsl:value-of select="Variable"/> = (dataRow.Table.Columns.Contains("<xsl:value-of select="Variable"/>")) ? dataRow["<xsl:value-of select="Variable"/>"] != DBNull.Value ? dataRow.Field<xsl:text disable-output-escaping="yes">&lt;decimal&gt;</xsl:text>("<xsl:value-of select="Variable"/>") : Decimal.Zero : Decimal.Zero<xsl:if test="position() != last()">,
        </xsl:if>
        </xsl:if>
        </xsl:for-each>
      };
      return item;
    }
    #endregion

    #region Public Methods
    public static List<xsl:text disable-output-escaping="yes">&lt;</xsl:text>AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity<xsl:text disable-output-escaping="yes">&gt;</xsl:text> Get_AUTO_<xsl:value-of select="$ObjectToOperate"/>_EntityList(DataTable dataTable)
    {
      List<xsl:text disable-output-escaping="yes">&lt;</xsl:text>AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity<xsl:text disable-output-escaping="yes">&gt;</xsl:text> result = new List<xsl:text disable-output-escaping="yes">&lt;</xsl:text>AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity<xsl:text disable-output-escaping="yes">&gt;</xsl:text>();
      foreach (DataRow dr in dataTable.Rows)
      {
        result.Add(BuildEntity(dr));
      }
        return result;
        }
    
        public static AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity Get_AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity(DataTable dataTable)
        {
            if (dataTable.Rows.Count <xsl:text disable-output-escaping="yes">&gt;</xsl:text> 0)
            {
                AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity result = new AUTO_<xsl:value-of select="$ObjectToOperate"/>_Entity();
                result = BuildEntity(dataTable.Rows[0]);
                return result;
            }
            return null;
        }
    #endregion

    #endregion

  }</xsl:template>

</xsl:stylesheet>